package com.caesar.Collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Scanner;
import java.util.function.Predicate;

/**
 * @author caesar
 * @date 2025/7/16
 * @Description:
 * @apiNote
 */
public class TestCollextion2 {
    public static void main(String[] args) {
        Collection<Integer> randNumbers = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            randNumbers.add((int) (Math.random() * 100));
        }
        System.out.println(randNumbers);

        Scanner input = new Scanner(System.in);
        System.out.print("请输入一个整数[0,100)： ");
        int number;
        while (true) {
            number = input.nextInt();
            if(number >= 0 && number < 100){
                break;
            } else{
                System.out.print("输入的整数超出范围，请重新输入：");
            }
        }
        //randNumbers.remove(number);//只能删除一个，面对重复的情况无法处理
        while(randNumbers.contains(number)){
            randNumbers.remove(number);
        }//循环删除，直到集合中不存在该元素

        System.out.println(randNumbers);

        Predicate<Integer> p = new Predicate<Integer>() {
            @Override
            public boolean test(Integer o) {
                return o % 10==3;
            }
        };
        randNumbers.removeIf(p);
        System.out.println(randNumbers);
        input.close();
    }
}
